using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace GameStateManagement
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Arrow : Actor
    {
        Player player;
        CheckpointManager manager;

        public Arrow(Game game, Player player, CheckpointManager manager_temp)
            : base(game)
        {
            // TODO: Construct any child components here
            sMeshName = "CheckpointArrow";
            this.player = player;
            m_vWorldPosition = Vector3.Zero;
            manager = manager_temp;
            bPhysicsDriven = false;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            //m_vWorldPosition = ship.m_vWorldPosition + ship.WorldTransform.Up * 200f;
            Checkpoint check = manager.GetCurrentCheckpoint();
            if (check != null)
            {
                m_vWorldPosition = player.m_Ship.m_vWorldPosition + 200f * player.m_Ship.WorldTransform.Up;
                Vector3 temp = check.m_vWorldPosition - m_vWorldPosition;
                temp = -temp;
                temp.Normalize();

                Vector3 tangent1 = Vector3.Cross(temp, WorldTransform.Up);
                tangent1.Normalize();
                Vector3 tangent2 = Vector3.Cross(tangent1, temp);
                tangent2.Normalize();

                WorldTransform.Forward = temp;
                WorldTransform.Right = tangent1;
                WorldTransform.Up = tangent2;
            }
        }

        public void get_new_manager(CheckpointManager temp)
        {
            manager = temp;
        }

    }
}
